<?php  
namespace Admin\Controller;
use Think\Controller; 
class UserController extends BaseController{
	function user(){
		$adminOb=M('Admin');
		$arr=$adminOb->field('admin.admin_username,admin.admin_id,auth_group.title,auth_group.id')
					 ->join('auth_group_access ON admin.admin_id=auth_group_access.uid')
					 ->join('auth_group ON auth_group_access.group_id = auth_group.id')
					 ->select();
		$groupOb=M('auth_group');
		$nameId=$groupOb->select();
		$this->assign('nameId',$nameId);
		$this->assign('arr',$arr);
		$this->display();
	}
	function check(){
		$adminOb=M('Admin');
		$group_id=$_POST['id'];
		unset($_POST['id']);
		$arr=$adminOb->data($_POST)->add();
		if ($arr) {
			$arr_id = $adminOb->where("admin_username = '{$_POST['admin_username']}'")->find();
			$uid=$arr_id['admin_id'];
			$data=array(
                'uid' => $uid,
                'group_id' => $group_id,
				);
			$authOb=M('Auth_group_access');
			$re=$authOb->data($data)->add();
			if ($re) {
                echo 1;
			}else{
                echo 0;
			}
		}else{
			echo 0;
		}
	}
	function user_upd(){
		$updOb=M('Auth_group_access');
		$arr=array('group_id'=>$_POST['group_id']);
		$re=$updOb->where("uid='{$_POST['uid']}'")->data($arr)->save();
		if ($re) {
			echo 1;
		}else{
			echo 0;
		}
	}
	function user_del(){
		$delAuth=M('Auth_group_access');
		$adminOb=M('Admin');
		$re=$adminOb->where("admin_id='{$_GET['admin_id']}'")->delete();
		if ($re) {
			$cRe=$delAuth->where("uid='{$_GET['admin_id']}'")->delete();
			if ($cRe) {
				echo 1;
			}else{
				echo 0;
			}
		}else{
			echo 0;
		}
	}
}